// 首页和商品云对象 - 整合pub、sys和基础功能
const { ProductController } = require('./controller/product.controller');
const { IndexController } = require('./controller/index.controller');
const { UploadController } = require('./controller/upload.controller');
const { MiddlewareUtils } = require('../middleware');

// 创建控制器实例
const productController = new ProductController();
const indexController = new IndexController();
const uploadController = new UploadController();

// 应用权限控制
// 公共接口：无需权限
// 基础接口：需要登录
// 系统管理接口：需要管理员权限

// 使用中间件装饰器对方法进行权限控制
const controllerWithMiddleware = {
    // ==================== 公共接口 (无需权限) ====================
    bannerList: indexController.bannerList.bind(indexController),
    menuList: indexController.menuList.bind(indexController),
    getRecommendProducts: indexController.getRecommendProducts.bind(indexController),
    categoryList: indexController.categoryList.bind(indexController),
    adsList: indexController.adsList.bind(indexController),
    getHotProducts: productController.getHotProducts.bind(productController),
    productCategoryList: productController.getCategories.bind(productController),
    searchProducts: productController.searchProducts.bind(productController),
    getRecommendations: productController.getRecommendations.bind(productController),
    getReviewStats: productController.getReviewStats.bind(productController),
    getNewProducts: productController.getNewProducts.bind(productController),
    getDistributionProducts: productController.getDistributionProducts.bind(productController),
	getProductList: productController.getProductList.bind(productController),
    getProductDetail: productController.getProductDetail.bind(productController),
    
    // ==================== 公共接口 - 文件上传 (无需权限) ====================
    uploadFile: uploadController.uploadFile.bind(uploadController),
    batchUploadFile: uploadController.batchUploadFile.bind(uploadController),
    
    // ==================== 系统管理接口 (需要管理员权限) ====================
    createProduct: MiddlewareUtils.requireAdmin(productController.createProduct.bind(productController)),
    updateProduct: MiddlewareUtils.requireAdmin(productController.updateProduct.bind(productController)),
    deleteProduct: MiddlewareUtils.requireAdmin(productController.deleteProduct.bind(productController)),
    batchChangeStatus: MiddlewareUtils.requireAdmin(productController.batchChangeStatus.bind(productController)),
    getProductStats: MiddlewareUtils.requireAdmin(productController.getProductStats.bind(productController)),
    batchUpdateStatus: MiddlewareUtils.requireAdmin(productController.batchUpdateStatus.bind(productController)),
    getReviewList: MiddlewareUtils.requireAdmin(productController.getReviewList.bind(productController)),
    reviewProduct: MiddlewareUtils.requireAdmin(productController.reviewProduct.bind(productController)),
    getOperationLogs: MiddlewareUtils.requireAdmin(productController.getOperationLogs.bind(productController)),
    
    
};

/**
 * 商品云对象
 * 提供完整的商品管理功能，整合了pub、sys和基础接口
 */
module.exports = controllerWithMiddleware;